<html><head>
      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
   <title>JoSQL</title><link rel="stylesheet" type="text/css" href="eclipse_book.css"><meta name="generator" content="DocBook XSL Stylesheets V1.77.1"><link rel="home" href="index.html" title="Red Hat Fuse Tooling"><link rel="up" href="RiderExLang.html" title="Part&nbsp;III.&nbsp;Expression and Predicates Languages"><link rel="prev" href="SpEL.html" title="SpEL"><link rel="next" href="XPath.html" title="The XPath Language"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a name="SQL"></a>JoSQL</h2></div></div></div><div class="simplesect"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="topic-33659"></a>Overview</h2></div></div></div><p>The JoSQL (SQL for Java objects) language enables you to evaluate predicates and
expressions in Apache Camel. JoSQL employs a SQL-like query syntax to perform selection and
ordering operations on data from in-memory Java objects&#8201;&#8212;&#8201;however, JoSQL is
<span class="strong"><strong>not</strong></span> a database. In the JoSQL syntax, each Java object instance is
treated like a table row and each object method is treated like a column name. Using this
syntax, it is possible to construct powerful statements for extracting and compiling data from
collections of Java objects. For details, see <a class="link" href="http://josql.sourceforge.net/" target="_top">http://josql.sourceforge.net/</a>.</p></div><div class="simplesect"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="topic-33660"></a>Adding the JoSQL module</h2></div></div></div><p>To use JoSQL in your routes you need to add a dependency on <code class="literal">camel-josql</code> to
your project as shown in <a class="xref" href="SQL.html#ExPredLangSQLEx060" title="Example&nbsp;20.&nbsp;Adding the camel-josql dependency">Example&nbsp;20, &#8220;Adding the camel-josql dependency&#8221;</a>.</p><div class="example"><a name="ExPredLangSQLEx060"></a><p class="title"><b>Example&nbsp;20.&nbsp;Adding the camel-josql dependency</b></p><div class="example-contents"><pre class="screen">&lt;!-- Maven POM File --&gt;
...
&lt;dependencies&gt;
  ...
  &lt;dependency&gt;
    &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
    &lt;artifactId&gt;camel-josql&lt;/artifactId&gt;
    &lt;version&gt;${camel-version}&lt;/version&gt;
  &lt;/dependency&gt;
  ...
&lt;/dependencies&gt;</pre></div></div><br class="example-break"></div><div class="simplesect"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="topic-33661"></a>Static import</h2></div></div></div><p>To use the <code class="literal">sql()</code> static method in your application code, include the
following import statement in your Java source files:</p><pre class="screen">import static org.apache.camel.builder.sql.SqlBuilder.sql;</pre></div><div class="simplesect"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="topic-33662"></a>Variables</h2></div></div></div><p><a class="xref" href="SQL.html#SQLAttTbl010" title="Table&nbsp;21.&nbsp;SQL variables">Table&nbsp;21, &#8220;SQL variables&#8221;</a> lists the variables that are accessible when using
JoSQL.</p><div class="table"><a name="SQLAttTbl010"></a><p class="title"><b>Table&nbsp;21.&nbsp;SQL variables</b></p><div class="table-contents"><table summary="SQL variables" border="1"><colgroup><col width="33%" class="col_1"><col width="33%" class="col_2"><col width="34%" class="col_3"></colgroup><thead><tr><th align="left" valign="top">Name</th><th align="left" valign="top">Type</th><th align="left" valign="top">Description</th></tr></thead><tbody><tr><td align="left" valign="top"><p><code class="literal">exchange</code></p></td><td align="left" valign="top"><p><code class="literal">org.apache.camel.Exchange</code></p></td><td align="left" valign="top"><p>The current Exchange</p></td></tr><tr><td align="left" valign="top"><p><code class="literal">in</code></p></td><td align="left" valign="top"><p><code class="literal">org.apache.camel.Message</code></p></td><td align="left" valign="top"><p>The IN message</p></td></tr><tr><td align="left" valign="top"><p><code class="literal">out</code></p></td><td align="left" valign="top"><p><code class="literal">org.apache.camel.Message</code></p></td><td align="left" valign="top"><p>The OUT message</p></td></tr><tr><td align="left" valign="top"><p><span class="emphasis"><em>property</em></span></p></td><td align="left" valign="top"><p><code class="literal">Object</code></p></td><td align="left" valign="top"><p>the Exchange property whose key is <span class="emphasis"><em>property</em></span></p></td></tr><tr><td align="left" valign="top"><p><span class="emphasis"><em>header</em></span></p></td><td align="left" valign="top"><p><code class="literal">Object</code></p></td><td align="left" valign="top"><p>the IN message header whose key is <span class="emphasis"><em>header</em></span></p></td></tr><tr><td align="left" valign="top"><p><span class="emphasis"><em>variable</em></span></p></td><td align="left" valign="top"><p><code class="literal">Object</code></p></td><td align="left" valign="top"><p>the variable whose key is <span class="emphasis"><em>variable</em></span></p></td></tr></tbody></table></div></div><br class="table-break"></div><div class="simplesect"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="topic-33663"></a>Example</h2></div></div></div><p><a class="xref" href="SQL.html#ExPredLangSQLEx090" title="Example&nbsp;21.&nbsp;Route using JoSQL">Example&nbsp;21, &#8220;Route using JoSQL&#8221;</a> shows a route that uses JoSQL.</p><div class="example"><a name="ExPredLangSQLEx090"></a><p class="title"><b>Example&nbsp;21.&nbsp;Route using JoSQL</b></p><div class="example-contents"><pre class="screen">&lt;camelContext&gt;
  &lt;route&gt;
    &lt;from uri="direct:start"/&gt;
    &lt;setBody&gt;
      &lt;language language="sql"&gt;select * from MyType&lt;/language&gt;
    &lt;/setBody&gt;
    &lt;to uri="seda:regularQueue"/&gt;
  &lt;/route&gt;
&lt;/camelContext&gt;</pre></div></div><br class="example-break"></div></div></body></html>